# 作业：
# 1、添加用户分组——》删除刚新增的用户分组
# 2、添加客服话术——》删除刚新增的客服话术
# 3、添加用户标签——》删除刚新增的用户标签
# 使用requests+pytest实现，每条用例要加上断言，对于新增的数据，要做关联
import pytest,requests
import uuid
class Test_CRMEB():
    project_url = "http://123.56.16.34:8899/"
    #@pytest.fixture(scope='function',autouse=True)
    def setup(self):
        response = requests.post(url = self.project_url + "/adminapi/login",json = {"account":"admin","pwd":"123456","imgcode":"a"})
        assert response.status_code == 200 # 先断言状态码是否是200
        assert response.json()['msg'] == 'ok'
        self.token = response.json()['data']['token']
        return "Bearer "+str(self.token)

    def test_user_group(self):
        # ===========================新增用户分组=========================================================================================
        self.uuid = str(uuid.uuid4()).split('-')[0]
        response = requests.post(url = self.project_url + "/adminapi/user/user_group/save.html",headers={"Authori-zation":self.setup()},
                                 json={"group_name":self.uuid + "刘闯大客户"})
        assert response.status_code == 200
        assert response.json()['msg'] == "提交成功！"

        # =========================查询用户分组======================================================================================
        response1 = requests.get(url = self.project_url + "/adminapi/user/user_group/list?page=1&limit=15",headers={"Authori-zation":self.setup()})
        assert response1.status_code == 200
        assert response1.json()['msg'] == 'ok'
        for i in response1.json()['data']['list']:
            if i['group_name'] == self.uuid + "刘闯大客户":
                self.id = i['id'] # 获取我想要删除的id

        # ===================删除用户分组===============================================================================================
        response2 = requests.delete(url = self.project_url + "/adminapi/user/user_group/del/" + str(self.id),headers={"Authori-zation":self.setup()})
        assert response2.status_code == 200
        assert response2.json()['msg'] =='删除成功!'

    def test_user_title(self):
        pass
    def test_user_message(self):
        pass











